package m.framework.test.web;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletInputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import m.framework.exception.SystemException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * httpServeletRequest的mock
 * 
 * @author ming
 * @date 2014年2月20日上午10:37:24
 */
public class RequestMock implements HttpServletRequest {
	private static Logger log = LoggerFactory.getLogger(RequestMock.class);
	private Map<String, Object> attibuteMap = new HashMap();
	private Map<String, String[]> parameterMap = new HashMap();
	private List<Cookie> cookies=new ArrayList();
	//请求路径
	private String requestURI;
	
	public void addCookie(String name,String value){
		Cookie ck=new Cookie(name,value);
		cookies.add(ck);
	}
	

	public void setRequestURI(String requestURI) {
		this.requestURI = requestURI;
	}

	public Object getAttribute(String name) {
		return attibuteMap.get(name);
	}

	public Enumeration getAttributeNames() {
		throw new SystemException("未实现");
	}

	public String getCharacterEncoding() {
		throw new SystemException("未实现");
	}

	public void setCharacterEncoding(String env) throws UnsupportedEncodingException {
		throw new SystemException("未实现");
	}

	public int getContentLength() {
		throw new SystemException("未实现");
	}

	public String getContentType() {
		throw new SystemException("未实现");
	}

	public ServletInputStream getInputStream() throws IOException {
		throw new SystemException("未实现");
	}

	public String getParameter(String name) {
		String[] value = parameterMap.get(name);
		if (value == null || value.length == 0) {
			return null;
		}
		return value[1];
	}

	public Enumeration getParameterNames() {
		throw new SystemException("未实现");
	}

	public String[] getParameterValues(String name) {
		return parameterMap.get(name);
	}

	public Map getParameterMap() {
		return parameterMap;
	}

	public String getProtocol() {
		throw new SystemException("未实现");
	}

	public String getScheme() {
		throw new SystemException("未实现");
	}

	public String getServerName() {
		throw new SystemException("未实现");
	}

	public int getServerPort() {
		throw new SystemException("未实现");
	}

	public BufferedReader getReader() throws IOException {
		throw new SystemException("未实现");
	}

	public String getRemoteAddr() {
		throw new SystemException("未实现");
	}

	public String getRemoteHost() {
		throw new SystemException("未实现");
	}

	public void setAttribute(String name, Object o) {
		attibuteMap.put(name, o);
	}

	public void removeAttribute(String name) {
		attibuteMap.remove(name);
	}

	public Locale getLocale() {
		throw new SystemException("未实现");
	}

	public Enumeration getLocales() {
		throw new SystemException("未实现");
	}

	public boolean isSecure() {
		throw new SystemException("未实现");
	}

	public RequestDispatcher getRequestDispatcher(String path) {
		throw new SystemException("未实现");
	}

	public String getRealPath(String path) {
		throw new SystemException("未实现");
	}

	public int getRemotePort() {
		throw new SystemException("未实现");
	}

	public String getLocalName() {
		throw new SystemException("未实现");
	}

	public String getLocalAddr() {
		throw new SystemException("未实现");
	}

	public int getLocalPort() {
		throw new SystemException("未实现");
	}

	public String getAuthType() {
		throw new SystemException("未实现");
	}

	public Cookie[] getCookies() {
		return cookies.toArray(new Cookie[cookies.size()]);
	}

	public long getDateHeader(String name) {
		throw new SystemException("未实现");
	}

	public String getHeader(String name) {
		throw new SystemException("未实现");
	}

	public Enumeration getHeaders(String name) {
		throw new SystemException("未实现");
	}

	public Enumeration getHeaderNames() {
		throw new SystemException("未实现");
	}

	public int getIntHeader(String name) {
		throw new SystemException("未实现");
	}

	public String getMethod() {
		throw new SystemException("未实现");
	}

	public String getPathInfo() {
		throw new SystemException("未实现");
	}

	public String getPathTranslated() {
		throw new SystemException("未实现");
	}

	public String getContextPath() {
		throw new SystemException("未实现");
	}

	public String getQueryString() {
		throw new SystemException("未实现");
	}

	public String getRemoteUser() {
		throw new SystemException("未实现");
	}

	public boolean isUserInRole(String role) {
		throw new SystemException("未实现");
	}

	public Principal getUserPrincipal() {
		throw new SystemException("未实现");
	}

	public String getRequestedSessionId() {
		throw new SystemException("未实现");
	}

	public String getRequestURI() {
		return requestURI;
	}

	public StringBuffer getRequestURL() {
		throw new SystemException("未实现");
	}

	public String getServletPath() {
		throw new SystemException("未实现");
	}

	public HttpSession getSession(boolean create) {
		throw new SystemException("未实现");
	}

	public HttpSession getSession() {
		throw new SystemException("未实现");
	}

	public boolean isRequestedSessionIdValid() {
		throw new SystemException("未实现");
	}

	public boolean isRequestedSessionIdFromCookie() {
		throw new SystemException("未实现");
	}

	public boolean isRequestedSessionIdFromURL() {
		throw new SystemException("未实现");
	}

	public boolean isRequestedSessionIdFromUrl() {
		throw new SystemException("未实现");
	}
	

}
